package net.nettytlv;

import java.util.concurrent.atomic.AtomicInteger;

import io.netty.util.AttributeKey;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Setter
@Getter
@ToString
public class Client {
    public static final AttributeKey<Client> KEY = AttributeKey.newInstance("CLIENT");

    public Client() {
        this.pingTime = new AtomicInteger(0);
        this.id = Long.valueOf(System.currentTimeMillis()).intValue();
    }

    private int id;

    /**
     * 心跳发送次数.
     */
    private AtomicInteger pingTime;

    /**
     * 心跳发送次数重置.
     */
    public void resetPingTime() {
        pingTime.set(0);
    }

    /**
     * 心跳发送次数是否超时.
     */
    public boolean isPingTimeout() {
        return pingTime.get() < 3;
    }
}